﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;

namespace VisualTest.Models
{
    class QuakeModel
    {
        public float? Longitude { get; set; }
        public float? Latitude { get; set; }
        public double? Magnitude { get; set; }
        public double? Depth { get; set; }
        public double? Date { get; set; }
        public string IconImage { get; set; }

        public void GenerateImage(string url)
        {
            int size = 20;
            String brush;

            if (Depth < 147) brush = "Red";
            else if (Depth < 294) brush = "Yellow";
            else if (Depth < 441) brush = "Green";
            else if (Depth < 588) brush = "Blue";
            else brush = "Purple";

            if (Magnitude < 3.0) size = size - 15;
            else if (Magnitude < 5.0) size = size - 10;
            else if (Magnitude < 7.0) size = size - 5;

            string imageUrl = brush + "_" + size.ToString() + ".png";

            if (File.Exists(url + imageUrl)) IconImage = "/quakes/Content/" + imageUrl;
            else
            {
                Brush b = new SolidBrush(Color.FromName(brush));
                Image canvas = new Bitmap(size, size);

                // create an object that will do the drawing operations
                Graphics artist = Graphics.FromImage(canvas);

                // draw a few shapes on the canvas picture
                artist.Clear(Color.Transparent);
                artist.FillEllipse(b, 0, 0, size, size);

                // now the drawing is done, we can discard the artist object
                artist.Dispose();

                canvas.Save(url + imageUrl);

                IconImage = "/quakes/Content/" + imageUrl;
            }
        }
    }
}
